package org.lbspoc.springboot1.boot.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.lbspoc.springboot1.boot.model.SimpleMessage;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;

@ControllerAdvice
@EnableAutoConfiguration
public class GlobalExceptionHandler {
	private static Logger logger = Logger.getLogger(GlobalExceptionHandler.class);

	@ExceptionHandler(HttpMessageNotReadableException.class)
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	@ResponseBody
    public SimpleMessage handleHttpMsgException(HttpServletRequest request, Exception ex) {
        logger.error(ex.getMessage(), ex);
		String message = ex.getMessage();
		return SimpleMessage.create(HttpStatus.INTERNAL_SERVER_ERROR.name(), message);
    }
     
    
	
	

}